<?
require_once($_SERVER['DOCUMENT_ROOT']."/common.inc");
require_once("leaguebase.func.inc");

define ('LEAGUE_LOGO', '../uploads/league_logo/');

//获取指定社团ID
$sid = isset($_GET['sid'])?intval($_GET['sid']):0;

$CurrSelMenu=4;
$Dbh = MyDB();
islogin(); //判断用户是否登录
$UsrInfo = unserialize($Session_UsrRealInfo); //获取登录用户信息

//require_once("../header.inc.php");
//require_once("member_left.inc.php");

$LeagueInfo = GetLeagueDetail($sid);
//echo $LeagueInfo['sid'];
$LeagueUsrRole = GetLeagueUsrRole($sid);


//获取社团活动信息
$sql = "select count(actid) from league_act_base where sid = $sid and isopen = 1";
//echo $sql;
$act_num = $Dbh->getOne($sql);
//echo $num;
//获取社团话题数
$sql = "select count(tid) from thread where tagid = $sid and isdel = 0";
//echo $sql;
$thread_num = $Dbh->getOne($sql);
//echo $thread_num;
//获取社团会员数
$sql = "select count(asuid) from usr_advert_league where sid = $sid";
//echo $sql;
$member_num = $Dbh->getOne($sql);


//每页活动显示数
$PageStep1 = 20;
$Pagetotal1 = ceil($act_num/$PageStep1);
$Request_p1 = isset($Request_p1)?intval($Request_p1):1;

//每页话题显示数
$PageStep2 = 20;
$Pagetotal2 = ceil($thread_num/$PageStep2);
$Request_p2 = isset($Request_p2)?intval($Request_p2):1;


//获取活动报名人数
//$League_Num = GetLeagueMemberNum(,'sid');
$sql = "select aid, count(aid) num from usr_advert_act group by aid";
$result = $Dbh->query($sql);
while($row = $result->fetchRow())$Act_Num[$row['aid']] = $row['num'];	

$sql1 = "select * from league_act_base where sid = $sid and isopen = 1 order by actid desc limit ".(($Request_p1-1)*$PageStep1).",".$PageStep1;
//echo $sql;
$result1 = $Dbh->query($sql1);
$sql2 = "select * from thread where tagid = $sid and isdel = 0 order by tid desc limit ".(($Request_p2-1)*$PageStep2).",".$PageStep2;
$result2 = $Dbh->query($sql2);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../styles/basic.css" />
<link rel="stylesheet" type="text/css" href="../styles/main.css" />
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="styles/ie.css" />
<![endif]-->
<script src='../js/domtab.js'></script>
<script src='../js/DOMhelp.js'></script>
<script src='../js/pagination.js'></script>
</head>
<body>
<div id='wrapper'>
	<h1>韭园<span>菊</span>色</h1>
    <p id="log"><a href="../signin.html">注册</a><a href="login.php">logout</a></p>
	<div class='content'>
    	<div class="main">
        	<h2 class="clubTitle"><? echo $LeagueInfo['cname']; ?><a class="button1" href="#">加入社团</a></h2>
            <div class="clubIntro">
<?
echo '<dl class="clubBasic">';
echo '<dt>简介</dt>';
echo '<dd class="clubLogo"><img alt="'.GetLeaguelogopath($LeagueInfo[regtime]).'" src="'.GetLeaguelogopath($rows[regtime]).' " /></dd>';
echo '<dd><span>简称:</span>'.$LeagueInfo['sname'].'</dd>';
echo '<dd><span>所属学校:</span>'.$LeagueInfo['schname'].'</dd>';
echo '<dd><span>成立时间:</span>'.date('Y年m月d日', $LeagueInfo['regtime']).'</dd>';
echo '<dd><span>社团性质:</span>'.$LeagueInfo['fname'].'</dd>';
echo '<dd><span>地址:</span>'.$LeagueInfo['address'].'</dd>';
echo '<dd><span>电话:</span>无电话</dd>';
echo '</dl>';
echo '<dl class="clubStatistics">';
echo '<dt>社团统计</dt>';
echo '<dd><span>活动:</span>'.$act_num.'个</dd>';
echo '<dd><span>会员:</span>'.$member_num.'个</dd>';
echo '<dd><span>话题:</span>'.$thread_num.'个</dd>';
echo '</dl>';
echo '</div>';
?>           
<!--
							 <dl class="clubBasic">
										<dt>简介</dt>         
                    <dd><span>简称:</span>八卦团</dd>
                    <dd><span>所属学校:</span>北京大学</dd>
                    <dd><span>成立时间:</span>2009年4月1日</dd>
                    <dd><span>社团性质:</span>文体</dd>
                    <dd><span>地址:</span>西环广场</dd>
                    <dd><span>电话:</span>7758521</dd>
                </dl>
                <dl class="clubStatistics">
                    <dt>社团统计</dt>
                    <dd><span>活动:</span>20个</dd>
                    <dd><span>会员</span>55个</dd>
                    <dd><span>话题:</span>1个</dd>
                </dl>
            </div>-->
            <div class="clubActivities">
                <h3>社团最新活动</h3>
                <ol>
<?
while($rows = $result1->fetchRow()){
	echo '<li>';
	echo '<h4><a href="#"><img alt="暂无活动图片" src="../images/activity2.jpg" />'.$rows['atitle'].'</a></h4>';
	echo '<p>'.$LeagueInfo['tenet'].'</p>';
	echo '<div>参加人数：'.$Act_Num[$rows[sid]].'人 <a class="button1" href="#">报名</a></div>';
	echo '</li>';
}
?>       
<!--         	
                    <li>
                        <h4><a href="#"><img src="../images/activity2.jpg" />我们去晒油</a></h4>
                        <p>科学松鼠会”是一个科学传播公益团体。成员包括来自国内外各院校的一线科研工作者……</p>
                        <div>参加人数：50人 <a class="button1" href="#">报名</a></div>
                    </li>
                    <li  class="noPhoto">
                        <h4><a href="#">我们去晒油</a></h4>
                        <p>科学松鼠会”是一个科学传播公益团体。成员包括来自国内外各院校的一线科研工作者……</p>
                        <div>参加人数：50人 <a class="button1" href="#">报名</a></div>
                    </li>
                    <li>
                        <h4><a href="#"><img src="../images/activity2.jpg" />我们去晒油</a></h4>
                        <p>科学松鼠会”是一个科学传播公益团体。成员包括来自国内外各院校的一线科研工作者……</p>
                        <div>参加人数：50人 <a class="button1" href="#">报名</a></div>
                    </li>
                    <li>
                        <h4><a href="#"><img src="../images/activity2.jpg" />我们去晒油</a></h4>
                        <p>科学松鼠会”是一个科学传播公益团体。成员包括来自国内外各院校的一线科研工作者……</p>
                        <div>参加人数：50人 <a class="button1" href="#">报名</a></div>
                    </li>
-->
                </ol>
            </div>

            <div class="clubTopics">
                <h3><span>话题讨论</span> <a class="button1" href="#">发表新话题</a></h3>
                <table>
                    <caption>话题列表</caption>
                    <thead>
                        <tr>
                            <th scope="col">话题</th>
                            <th scope="col">发起者</th>
                            <th scope="col">回复人数</th>
                            <th scope="col">发起时间</th>
                        </tr>
                    </thead>
                    <tbody>
<?
while($rows = $result2->fetchRow()){
	echo '<tr>';
	echo '<th scope="row"><a href="#">'.$rows['title'].'</a></th>';
	echo '<td><a href="#">'.$rows['username'].'</a></td>';
	echo '<td>'.$rows['replynum'].'</td>';
	echo '<td>'.date('Y-m-d H:m' ,$rows['lastpost']).'</td>';
	echo '</tr>';
}
?>     
<!--               	
                        <tr>
                            <th scope="row"><a href="#">科学松鼠会招募实习生：加入我们，分享科学</a></th>
                            <td><a href="#">纪晓芙</a></td>
                            <td>43</td>
                            <td>2009-04-23 19:35</td>
                        </tr>
                        <tr>
                            <th scope="row"><a href="#">科学松鼠会招募实习生：加入我们，分享科学</a></th>
                            <td><a href="#">纪晓芙</a></td>
                            <td>43</td>
                            <td>2009-04-23 19:35</td>
                        </tr>
                        <tr>
                            <th scope="row"><a href="#">科学松鼠会招募实习生：加入我们，分享科学</a></th>
                            <td><a href="#">纪晓芙</a></td>
                            <td>43</td>
                            <td>2009-04-23 19:35</td>
                        </tr>
                        <tr>
                            <th scope="row"><a href="#">科学松鼠会招募实习生：加入我们，分享科学</a></th>
                            <td><a href="#">纪晓芙</a></td>
                            <td>43</td>
                            <td>2009-04-23 19:35</td>
                        </tr>
                        <tr>
                            <th scope="row"><a href="#">科学松鼠会招募实习生：加入我们，分享科学</a></th>
                            <td><a href="#">纪晓芙</a></td>
                            <td>43</td>
                            <td>2009-04-23 19:35</td>
                        </tr>
                        <tr>
                            <th scope="row"><a href="#">科学松鼠会招募实习生：加入我们，分享科学</a></th>
                            <td><a href="#">纪晓芙</a></td>
                            <td>43</td>
                            <td>2009-04-23 19:35</td>
                        </tr>
-->                        
                    </tbody>
                </table>
            </div>
        </div>
        <div class="side">
			<div class="tabs clubInformation">
				<ul class="tabNav">
					<li><a href="#tab1">社团公告</a></li>
					<li><a href="#tab2">社团组织结构</a></li>
					<li><a href="#tab3">了解社团历史</a></li>
				</ul>
				<div id="tab1" class="sideWidget">
					<h3>社团公告</h3>
					<p><? echo $LeagueInfo['tenet']; ?></p>
				</div>
				<dl id="tab2" class="sideWidget">
					<dt>社团组织结构</dt>
<?
foreach($LeagueUsrRole as $ur)
{
	echo '<dd><span>'.$ur['ename'].': </span>'.$ur['cname'].'</dd>';
}
?>					
<!--
					<dd><span>社长:</span>像一名</dd>
					<dd><span>社长:</span>像一名</dd>
					<dd><span>社长:</span>像一名</dd>
					<dd><span>社长:</span>像一名</dd>
					<dd><span>社长:</span>像一名</dd>
					<dd><span>社长:</span>像一名</dd>
-->					
				</dl>
				<div id="tab3" class="sideWidget">
					<h3>了解社团历史</h3>
					<p><? echo $LeagueInfo['sbio']; ?></p>
				</div>
			</div>	
            <div class="sideWidget userPhotoList">
            	<h3>社团成员</h3>
                <ul>
                	<li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
                    <li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
					<li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
                    <li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
					<li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
                    <li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
					<li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
                    <li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
                </ul>
                <p class="clear">>><a href="">浏览所有社团成员</a></p>
            </div>
            <div class="sideWidget userPhotoList">
            	<h3>友情社团</h3>
                <ul>
                	<li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
                    <li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
					<li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
                    <li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
					<li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
                    <li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
					<li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
                    <li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
                </ul>
            </div>
<div class="sideWidget ">
            	<h3>其他社团热门活动</h3>
            	<ol>
            		<li><a href="#">我们是想建设一个针对高校社团的网络平台</a></li>
                	<li><a href="#">我们是想建设一个针对高校社团的网络平台</a></li>
					<li><a href="#">我们是想建设一个针对高校社团的网络平台</a></li>
					<li><a href="#">我们是想建设一个针对高校社团的网络平台</a></li>
					<li><a href="#">我们是想建设一个针对高校社团的网络平台</a></li>
            	</ol>
        	</div>
            <div class="sideWidget userPhotoList">
            	<h3>关注企业</h3>
                <ul>
                	<li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
                    <li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
					<li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
                    <li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
					<li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
                    <li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
					<li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
                    <li><a href="#"><img src="../images/clubLogo.jpg" />圣斗士星矢</a></li>
                </ul>
            </div>
        </div>
    </div>
    
	<ul id='nav'>
		<li><a href="../index.html">首页</a></li>
		<li><a href="../associator/index.html">个人首页</a></li>
		<li><a href="">好友</a></li>
		<li><a href="">通知</a></li>
		<li><a href="">个人设置</a></li>
		<li><a href="">搜索</a></li>
    	<li class='last'><a href="">日志</a></li>	
	</ul>
	<div id="footer">
		<ul>
			<li class="noBd"><a href="">Home</a></li>
			<li><a href="">注册</a></li>
			<li><a href="">登陆</a></li>
			<li><a href="">href3</a></li>
			<li><a href="">href3</a></li>
			<li><a href="">href3</a></li>
			<li><a href="">href3</a></li>			
		</ul>
        <p>All rights deserves &copy; <span class="cap">社团</p>
    </div>
</div>
</body>
</html>

<?
/*
 * 获取社团详细信息，包括社团基本信息，对应所属社团分类，所属学校等...
 * 输入 社团id  输出 社团详细信息数组
 */
function GetLeagueDetail($sid)
{
	global $Dbh;
	$dhh = $Dbh;
	if(!is_object($dhh))$dhh = MyDB();
	
	if(empty($sid))return -1;
	$Query = "select a.*, b.cname as schname, c.fname, d.sbio from league_info a, other_school b, league_class c, league_bio d where a.schid = b.schid  and a.scid = c.scid and a.sid = d.sid and a.sid='$sid'";
	$Sth = $dhh->query($Query);
	$Rows = $Sth->fetchRow();
	unset($dhh);
	if(empty($Rows))return -2;
	return $Rows;	
}

/**
 * 获取社团对应管理人员信息
 *
 */
function GetLeagueUsrRole($sid)
{
	global $Dbh;
	$dhh = $Dbh;
	if(!is_object($dhh))$dhh = MyDB();
	
	$Rows = Array();
	
	if(empty($sid))return -1;
	$Query = "select * from league_user_role where sid = $sid";
	$Sth = $dhh->query($Query);
	while($r = $Sth->fetchRow()){
		array_push($Rows, $r);
	}
	unset($dhh);
	if(empty($Rows))return -2;
	return $Rows;	
}
?>